package dictionary;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JTextArea;
import java.awt.event.ActionListener;
import java.util.Iterator;
import java.util.LinkedList;
import java.awt.event.ActionEvent;

public class Dir extends JFrame {

	private JPanel contentPane;
	private JTextField input;
	
	private LinkedList<Record>content=new LinkedList<Record>();

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Dir frame = new Dir();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Dir() {
		Record r[]=new Record[8];
		r[0]=new Record("God","上帝");
		r[1]=new Record("Japanese","小日本");
		r[2]=new Record("日本","Japan");
		r[3]=new Record("做什么","doing what");
		r[4]=new Record("你好","hello");
		r[5]=new Record("hello","你好");
		r[6]=new Record("上帝","god");
		r[7]=new Record("doing what","做什么");
		for(Record i:r) 
			content.add(i);
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		input = new JTextField();
		
		input.setBounds(32, 67, 174, 44);
		contentPane.add(input);
		input.setColumns(10);
		JTextArea output = new JTextArea();
		output.setBounds(32, 121, 310, 132);
		contentPane.add(output);
	
		
		JButton search = new JButton("search");
		search.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String str=input.getText();
				                                                   
					Iterator<Record> it=content.iterator();
					Record re;
					boolean flag = true;
					while(it.hasNext()) {
						re=it.next();
						if(re.english.equals(str)  ) {
							flag = false;
							output.setText(re.chinese);
							
						}									
					}
					if(flag) {
						output.setText("no search!");
						
					}
								                                                                           			
			}
		});
		search.setBounds(223, 69, 157, 39);
		contentPane.add(search);
		
		
	}
}
